package ar.com.gtug.util;

import java.util.List;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


public class MailService {

	public static void sendMessage(String title, String message, String from, String to) {
		try {

			Properties props = new Properties();
			Session session = Session.getDefaultInstance(props, null);
			Message msg = new MimeMessage(session);
			msg.setFrom(new InternetAddress(from,"GTUG Apps"));
			msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to,
					"Usuario GTUG Apps"));
			msg.setSubject(title);
			msg.setText(message);
			Transport.send(msg);
			

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void sendMessage(String title,String message, String from, List<String> toList) {
		try {

			Properties props = new Properties();
			Session session = Session.getDefaultInstance(props, null);
			Message msg = new MimeMessage(session);
			msg.setFrom(new InternetAddress(from));
			for (String to : toList) {
				msg.addRecipient(Message.RecipientType.TO, new InternetAddress(
						to, "Usuario GTUG Apps"));
			}
			msg.setSubject(title);
			msg.setText(message);
			Transport.send(msg);
			

		} catch (Exception e) {
			e.printStackTrace();
		}
	}	

//	public void sendMailToAdmins(String title,String message){
//		List<String> admins = new ArrayList<String>();
//		admins.add("juan@irungaray.com.ar");
//		sendMessage(title, message, "alerts@univercv.com.ar", admins);
//	}
}
